﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using crmquanlynhansu.BusinessObject;
using LifeSoftLibary;
using System.Data;
using System.Data.SqlClient;

namespace crmquanlynhansu.DataLayer
{
    class DepartmentData
    {
        SqlConnection conn = new SqlConnection(new ConnectUtils().SQL_CONNECTION_STRING);
        private SqlCommand cmd;
        public bool InsertDepartment(DepartmentInfo info)
        {
            try
            {
                string sql = "INSERT INTO BS_DEPARTMENT VALUES(";
                sql += "'" + info.departmentCode + "', ";
                sql += "N'" + info.departmentName + "', ";
                sql += info.phone + ", ";
                sql += info.fax + ", ";
                sql += 0 + ", ";
                sql += info.baseUnitId + ")";

                cmd = new SqlCommand(sql, conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                return true;
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }

        public bool UpdateDepartment(DepartmentInfo info)
        {
            try
            {
                string sql = "UPDATE BS_DEPARTMENT SET ";
                sql += "BS_DEPARTMENT_CODE = '"+ info.departmentCode +"', ";
                sql += "BS_DEPARTMENT_NAME =";
                return true;
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }
    }
}
